//
//  LYSettingDetailView.m
//  SZBank
//
//  Created by LuoYao on 16/7/14.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "LYSettingDetailView.h"

@interface LYSettingDetailView ()<UIScrollViewDelegate>
@property (nonatomic) UIScrollView *scrollView;/**< 滚动视图 */
@property (nonatomic) UIPageControl *pageControl;/**< 页面指示器 */
@property (nonatomic) UITextView *inputTextView;/**< 输入框 */
@property (nonatomic) UIButton *cancelBtn;/**< 返回按钮 */

@end
@implementation LYSettingDetailView

- (instancetype)initWithFrame:(CGRect)frame style:(LYSettingDetailViewStyle)style title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        self.autoresizesSubviews = NO;
        
        //backView
        UIImageView *backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _cKwidth, _cKheight)];
        backImageView.userInteractionEnabled = YES;
        
        backImageView.image = [LocalDataManager getImageWithSourceOfPath:@"关于我行_背景"];
        [self addSubview:backImageView];
        [backImageView addSubview:self.cancelBtn];
        
        //title
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _cKwidth, _cKheight * 0.1)];
        titleLabel.text = title;
        titleLabel.font = [UIFont systemFontOfSize:FONT_SIZE];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:titleLabel];
        
        
        switch (style) {
            case LYSettingDetailViewStyleAbountMe:
            {
                UIImage *image = [LocalDataManager getImageWithSourceOfPath:@"关于我行_内容"];
                UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.width / image.size.width * image.size.height)];
                imageView.image = image;
                
                self.scrollView.showsVerticalScrollIndicator = NO;
                self.scrollView.backgroundColor = [UIColor whiteColor];
                self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width, self.scrollView.frame.size.width / image.size.width * image.size.height);
                [self.scrollView addSubview:imageView];
                
                [backImageView addSubview:self.scrollView];
            }
                break;
                
            case LYSettingDetailViewStyleSystem:
            {
                UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(_cKwidth * 0.2, _cKheight * 0.25, _cKwidth * 0.6, _cKheight * 0.5)];
                imageView.image = [LocalDataManager getImageWithSourceOfPath:@"用户中心_版本信息_苏州银行"];
                imageView.contentMode = UIViewContentModeScaleAspectFit;
                
                [backImageView addSubview:imageView];
            }
                break;
                
            case LYSettingDetailViewStyleUser:
            {
                NSArray *imageNames= @[@"用户指南_1",@"用户指南_2",@"用户指南_3",@"用户指南_4",@"用户指南_5"];
                for (int i = 0; i < imageNames.count; i ++) {
                    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.frame.size.width * 0.8, 0, self.frame.size.width * 0.8, self.frame.size.height * 0.7)];
                    imageView.image = [LocalDataManager getImageWithSourceOfPath:imageNames[i]];
                    [self.scrollView addSubview:imageView];
                }
                self.scrollView.contentSize = CGSizeMake(self.frame.size.width * 0.8 * imageNames.count, self.frame.size.height * 0.7);
                
                [self addSubview:self.pageControl];
                [backImageView addSubview:self.scrollView];
                
                
            }
                break;
                
                
            case LYSettingDetailViewStyleText:
            {
                UIImageView *textImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_cKwidth * 0.1, _cKheight *0.2, _cKwidth * 0.8, _cKheight * 0.6)];
                textImageView.image = [LocalDataManager getImageWithSourceOfPath:@"用户反馈_背景"];
                textImageView.userInteractionEnabled = YES;
                
                UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(textImageView.frame.size.width * 0.7, textImageView.frame.size.height *0.8, textImageView.frame.size.width * 0.2, textImageView.frame.size.height * 0.1)];
                [sureBtn setBackgroundImage:[LocalDataManager getImageWithSourceOfPath:@"用户反馈_提交反馈"] forState:UIControlStateNormal];
                [sureBtn addTarget:self action:@selector(action_sureBtn) forControlEvents:UIControlEventTouchUpInside];
                
                [textImageView addSubview:sureBtn];
                
                [backImageView addSubview:textImageView];
                
                UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(_cKwidth * 0.15, _cKheight *0.2, _cKwidth * 0.7, _cKheight * 0.5)];
                textView.font = [UIFont systemFontOfSize:FONT_SIZE];
                textView.backgroundColor = [UIColor clearColor];
                [backImageView addSubview:textView];
                
                
            }
                break;
                
            default:
                break;
        }
        
    }
    return self;
}


#pragma mark - action_cancelBtn
- (void)action_cancelBtn{
    [self removeFromSuperview];
}

- (void)action_sureBtn{
    [LocalDataManager addAlertControllerWithControllerTitle:@"温馨提示" controllerMessage:@"感谢你的反馈，我们将尽快研究是不是需要改正。" actionSureTitle:@"确认" actionCancelTile:nil actionSureBlock:nil actionCancelBlock:nil style:0];
}

#pragma mark - UIScorllViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //计算偏移量
    CGFloat index = scrollView.contentOffset.x / [[[NSString stringWithFormat:@"%lf",_cKwidth * 0.8] substringFromIndex:0] integerValue];
    
    self.pageControl.currentPage = index;
}

#pragma mark - getter
- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _cKheight * 0.2, self.frame.size.width * 0.8, _cKheight * 0.7)];
        _scrollView.center = self.center;
        _scrollView.delegate = self;
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = NO;
//        _scrollView
        
        [_scrollView addSubview:self.pageControl];
    }
    return _scrollView;
}

- (UIPageControl *)pageControl{
    if (!_pageControl) {
        _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(_cKwidth * 0.4, _cKheight * 0.8, _cKwidth * 0.2, 30)];
        _pageControl.currentPage = 0;
        _pageControl.numberOfPages = 5;
        _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
        _pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    }
    return _pageControl;
}

- (UITextView *)inputTextView{
    if (!_inputTextView) {
        _inputTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, _cKwidth * 0.8, _cKheight * 0.6)];
        _inputTextView.center = CGPointMake(self.center.x, _cKheight * 0.4);
    }
    return _inputTextView;
}

- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(_cKwidth * 0.05, _cKheight * 0.05, 80, 35)];
        [_cancelBtn setBackgroundImage:[LocalDataManager getImageWithSourceOfPath:@"关于我行_返回"] forState:UIControlStateNormal];
        [_cancelBtn addTarget:self action:@selector(action_cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}
@end
